Skip to main content
ik_llama.cpp supports OpenAI-style function calling through Jinja chat templates. When the server is started with --jinja, it parses tool definitions from incoming requests, formats them according to the model’s chat template, and extracts tool calls from the model’s response.
You must start llama-server with the --jinja flag to enable function calling. Without it, tool definitions in API requests are ignored.

Native and generic handlers

Function calling works with all models, but the quality depends on which format handler is selected: Native handlers parse tool calls using model-specific logic. They produce the most reliable results. The following model families have native support:
  • Llama 3.1 / 3.2 / 3.3 (including built-in tools: wolfram_alpha, web_search / brave_search, code_interpreter)
  • Qwen 2.5 and Qwen 2.5 Coder
  • Hermes 2 and Hermes 3
  • Mistral Nemo
  • Firefunction v2
  • Command R7B
  • Functionary v3.1 / v3.2
  • DeepSeek R1 (WIP — the model is reluctant to call tools)
Generic handler is used when the chat template is not recognised by any native handler. You will see Chat format: Generic in the server logs. Generic mode works but may consume more tokens and be less efficient than a model’s native format.

Starting the server

Native support (no template override needed)

The official DeepSeek R1 chat template has known issues. Use the bundled override:

Models that require a template override

Some GGUF files embed an incorrect or default (non-tool-use) template. Pass the correct template with --chat-template-file:

Generic format models

These work out of the box with --jinja, using the generic handler:

Chat template override

If a model’s embedded template is buggy or missing tool-use support, download the correct .jinja file and pass it with --chat-template-file. This avoids re-downloading the full GGUF:
To retrieve the official template from a HuggingFace repository:
If no official tool_use template exists for your model, try --chat-template chatml. It works with many models as a fallback, though results vary.

Making a tool call request

Use the standard OpenAI /v1/chat/completions endpoint with a tools array:
A successful response looks like:

KV cache and tool calling quality

Extreme KV cache quantizations (e.g. -ctk q4_0) can substantially degrade tool calling performance. Use -ctk q8_0 or -ctk q6_0 when running function-calling workloads. For very aggressive quantization below Q6_0, add --k-cache-hadamard to partially recover quality.

Verifying the active template

To confirm which template and format handler the server selected, check the /props endpoint after startup:
The server logs also print the detected chat format (e.g. Chat format: Hermes 2 Pro or Chat format: Generic) at startup.